﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MusicService
{
    public partial class MusicService: IGenreService
    {
        public void addGenre(string genreName)
        {
            Genre genre = new Genre();
            int numberGenre = dc.Genres.Count() + 1;
            genre.GenreID = "GENRE"+numberGenre;
            genre.GenreName = genreName;
            dc.Genres.InsertOnSubmit(genre);
            dc.SubmitChanges();
        }

        public bool editGenre(string genreID, string genreName)
        {
            Genre genre = dc.Genres.First(c=>c.GenreID.Equals(genreID));
            if (genre != null)
            {
                genre.GenreName = genreName;
                dc.SubmitChanges();
                return true;
            }
            return false;
        }

        public bool removeGenre(string genreID)
        {
            Genre genre = dc.Genres.First(c => c.GenreID.Equals(genreID));
            if (genre != null)
            {
                dc.Genres.DeleteOnSubmit(genre);
                dc.SubmitChanges();
                return true;
            }
            return false;
        }

        public List<Genre> getListGenre()
        {
            var list = from c in dc.Genres select c;
            return list.ToList<Genre>();
        }
    }
}